package com.winit.dataInit;

import com.winit.Application;
import com.winit.feature.model.Feature;
import com.winit.feature.repository.FeatureOperations;
import com.winit.feature.repository.FeatureRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.Iterator;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class)
public class UpdateSysToUpperCase {

    @Autowired
    private FeatureRepository featureRepository;
    @Autowired
    private FeatureOperations featureOperations;


    @Test
    public void changeAllFeatureSysToUpper(){
        Iterable<Feature> iterable = featureRepository.findAll();
        Iterator<Feature> features = iterable.iterator();
        Feature temp = null;
        while (features.hasNext()){
            temp = features.next();
            Feature update = new Feature();
            update.setId(temp.getId());
            update.setSys(temp.getSys().toUpperCase());
            this.featureOperations.updatePropertiesNotNullById(update);
        }
    }
}
